package com.ssyt.intercepor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;




public class MethodIntercepor extends MethodFilterInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
/**
 * 拦截器处理类
 * 首先继承MethodFilterInterceptor该类 
 * ActionInvocation action的代理对象
 */
	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		 String result=null;
		 System.out.println("进入拦截器");
		 //获取别拦截的action上下文
		 ActionContext context=invocation.getInvocationContext();
		 //获取当前用户 
		 Object obj = context.getSession().get("user");
		 if(obj!=null){
			 //放行当前该session 所访问的action对应的方法
			 result=invocation.invoke();
			 
		 }else {
			 result=Action.LOGIN;
			 context.put("msg", "您没有登陆");
		}
		return result;
	}

}
